<?php
App::uses('AppModel', 'Model');
/**
 * SubscriptionTerm Model
 *
 * @property Subscription $Subscription
 */
class SubscriptionTerm extends AppModel {
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';
/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'term' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'Subscription' => array(
			'className' => 'Subscription',
			'foreignKey' => 'subscription_term_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
        
        public function getTermId($plan) {
            $term = $this->find('first', array('conditions' => array('SubscriptionTerm.term' => $plan)));
            return $term['SubscriptionTerm']['id'];
        }
        
        public function getPlan($id) {
           $term = $this->find('first', array('conditions' => array('SubscriptionTerm.id' => $id))); 
           return $term['SubscriptionTerm']['term'];
        }
        public function getPrice($id) {
             $term = $this->find('first', array('conditions' => array('SubscriptionTerm.id' => $id))); 
              return $term['SubscriptionTerm']['price'];
        }
}
